from datetime import datetime

# 中文词语模型类
class ChineseWordsModel:
    def __init__(self, id, phrase, pinyin, meaning, example_sentence=None, pinyin_letters=None,type=None,audio_url=None,hot=None, created_at=None, updated_at=None):
        self.id = id
        self.phrase = phrase
        self.pinyin = pinyin
        self.meaning = meaning
        self.example_sentence = example_sentence
        self.pinyin_letters = pinyin_letters
        self.type = type
        self.audio_url = audio_url
        self.hot = hot
        # 添加时间字段
        self.created_at = created_at
        self.updated_at = updated_at
    
    def to_dict(self):
        return {
            'id': self.id,
            'phrase': self.phrase,
            'pinyin': self.pinyin,
            'meaning': self.meaning,
            'example_sentence': self.example_sentence,
            'pinyin_letters': self.pinyin_letters,
            'type': self.type,
            'audio_url': self.audio_url,
            'hot': self.hot,
            'created_at': self.created_at.isoformat() if isinstance(self.created_at, datetime) else self.created_at,
            'updated_at': self.updated_at.isoformat() if isinstance(self.updated_at, datetime) else self.updated_at
        }